//
//  CRResetPasswordView.m
//  CRChatRoom
//
//  Created by CuiFengshuai on 15/11/26.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRResetPasswordView.h"
#import "CRUserManager.h"

@interface CRResetPasswordView ()

@property (nonatomic, strong) CRUserManager *manager;

@end

@implementation CRResetPasswordView
#pragma mark >>>>懒加载

- (CRUserManager *)manager {
    if (!_manager) {
        _manager = [CRUserManager new];
    }
    return _manager;
}

+ (instancetype)resetPasswordByPhone {
    return [[NSBundle mainBundle] loadNibNamed:@"CRResetPasswordView" owner:nil options:nil].lastObject;
}

- (void)resetPasswordByPhone {
    // 判断两次输入的密码是否一致
    if (![self.pwdText.text isEqualToString:self.turePwdText.text]) {
        NSLog(@"两次输入不一致");
        
        return;
    }
    
    [self.getCodeButton addTarget:self action:@selector(didClickGetCodeButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.resetPwdButton addTarget:self action:@selector(didClickResetPwdButton:) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark >>>> 按钮点击事件监听方法
- (void)didClickGetCodeButton:(UIButton *)button {
    // 获取验证码
    [self.manager requestPasswordResetWithPhoneNumber:self.phoneNumber.text success:^{
        NSLog(@"获取成功");
    } failure:^(NSError *error) {
        NSLog(@"获取失败");
    }];
}

- (void)didClickResetPwdButton:(UIButton *)button {
    // 修改密码
    [self.manager resetPasswordWithSmsCode:self.codetext.text newPassword:self.pwdText.text success:^{
        NSLog(@"修改成功");
    } failure:^(NSError *error) {
        NSLog(@"修改失败");
    }];
}

@end
